import { GetuserX, IUserInfo } from '@api/user'
import { Role } from '@interface/user'
import { defineStore } from 'pinia'
export const useUserStore = defineStore('userId', {
  state: (): {
    rolePerm: string
    roles: Role[]
    userInfo: Partial<IUserInfo>
  } => {
    return {
      roles: [],
      rolePerm: '',
      userInfo: {}
    }
  },
  getters: {},
  actions: {
    async Getinfo() {
      const res = await GetuserX()
      // 获取用户列表
      this.roles = res.data.roles
      //角色信息
      this.rolePerm = res.data.roles[0].rolePerm
    }
  },
  persist: {
    enabled: true, //开启数据缓存
    strategies: [
      {
        storage: localStorage, //默认走session
        // 是否存入指定的值
        paths: ['rolePerm', 'userInfo']
      }
    ]
  }
})
